/*=============================================================
(c) 2012 by Juliano Efson Sales
www.mdcc.ufc.br
================================================================*/

using System.Xml;
using System.Collections.Generic;
using HPE.Base;

namespace HPE.Load {
   //classe para colaborar com a geração de uma configuration.
   public class TempTransition {
      public int action;
      public XmlNode node;
      public int preState;
      public int posState;
      public bool isElse;
      
      public TempTransition(int action, int preState, int posState, bool isElse) {
         this.action = action;
         this.preState = preState;
         this.posState = posState;
         this.isElse = isElse;
      }
      
      public TempTransition(XmlNode node, int preState, int posState) {
         this.node = node;
         this.preState = preState;
         this.posState = posState;
      }
      
      //Método usado para inserir um elemento no Hashtable. Deverá ser utilizado este método porque ele faz uma associação da Transition com uma lista.
      public static void insertTransitionListMap(TempTransition tran, System.Collections.Hashtable hash) {
         
         Queue<TempTransition> queue = (Queue<TempTransition>) hash[tran.preState];
         
         if(queue == null) {
            queue = new Queue<TempTransition>();
            queue.Enqueue(new TempTransition(Configuration.NOTHING, tran.preState, Configuration.NOTHING, true));
            hash.Add(tran.preState, queue);
         }
         
         if(tran.isElse) {
            queue.Dequeue();
         }
         
         queue.Enqueue(tran);
      }

      public string toString() {
         string s = "action: " + action + "| ";
         if(node != null) {
            s += "node: " + node.Name + "| ";
         }
          s += "preState: " + preState + "| ";
          s += "posState: " + posState + "| ";
          s += "isElse: " + isElse;

         return s;
      }
   }
}
